//
//  def_declaration_list.h
//  compilation
//
//  Created by Kevin Le perf on 17/01/12.
//  Copyright (c) 2012 e2co technologie. All rights reserved.
//

#ifndef compilation_def_declaration_list_h
#define compilation_def_declaration_list_h

/*
 declaration_list
 : declaration {printf("declaration_list\n");}
 | declaration_list declaration {printf("declaration_list\n");}
 ; 
 */

struct def_declaration_list{
	void * parent;
	int type;
	struct def_declaration * declaration;
	struct def_declaration_list * declaration_list;
	
	struct symbol * _symbols[255];
	int _count;
};

struct def_declaration_list * declaration_list_create(void * parent){
	struct def_declaration_list * d = malloc(sizeof(*d));
	d->type = 0;
	d->parent = parent;
	d->_count = 0;
	d->declaration_list = NULL;
	d->declaration = NULL;
	return d;
}

void declaration_list_compute(struct def_declaration_list * d){
	struct def_declaration_list * cursor = d;
	while(cursor != NULL){
		int i;
		printf("eeee\n");
		for(i=0;cursor->declaration != NULL && i<cursor->declaration->_count;i++){
			printf("adding new var to declaration %s", cursor->declaration->_symbols[i]->_name);
			d->_symbols[d->_count] = cursor->declaration->_symbols[i];
			d->_count++;
		}
		cursor = cursor->declaration_list;
	}
}

void declaration_list_print(struct def_declaration_list * d){
	int i=0;
	switch(d->type){
		case 2:
			declaration_list_print(d->declaration_list);
			printf(" ");
		case 1:
			declaration_print(d->declaration);
			break;
		case 3:
			for(;i<d->_count;i++){
				symbol_print(d->_symbols[i]);
				printf(";\n");
			}
	}
}
#endif
